<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>弹框示例</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        #box {
            position: relative;
            width: 200px;
            height: 200px;
            cursor: pointer;
            overflow: hidden;
            border-radius: 5px;
        }
        #box img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .mask {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(255, 255, 255, 0.5);
            display: none;
        }
        #box:hover .mask {
            display: block;
        }
        .masks {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100vh;
            background-color: rgba(0, 0, 0, 0.8);
            display: flex;
            justify-content: center;
            align-items: center;
            visibility: hidden;
            opacity: 0;
            transition: visibility 0.3s ease, opacity 0.3s ease;
            z-index: 1000;
        }
        .masks.show {
            visibility: visible;
            opacity: 1;
        }
        
        .close-btn {
            position: absolute;
            top: 1rem;
            right: 1rem;
            width: 30px;
            height: 30px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 20px;
            color: #fff;
            cursor: pointer;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }
        .description {
            text-align: center;
            color: #fff;
            margin-top: 1rem;
            font-size: 18px;
        }
        
    </style>
</head>
<body>
    <div id="box">
        <img src="./img/GitHub头像.jpg" alt="GitHub 头像图片">
        <div class="mask"></div>
    </div>
    <div class="masks">
        <div class="masks-content">
            <img src="" alt="">
            <!-- 文字描述容器 -->
             <div class="description"></div>
            <div class="close-btn">&times;</div>
        </div>
    </div>
    <script>
        const box = document.getElementById('box');
        const masks = document.querySelector('.masks');
        const masksImg = masks.querySelector('img');
        const closeBtn = masks.querySelector('.close-btn');
        const description = masks.querySelector('.description');

        box.onclick = function () {
            const smallImgSrc = box.querySelector('img').src;
            masksImg.src = smallImgSrc;
            //设置大图片的属性
            masksImg.style.width = '500px';
            masksImg.style.height = '500px';
            masksImg.style.objectFit = 'contain';
            masks.classList.add('show');

            // 设置文字描述
            description.textContent = '这是一个示例图片';

        };

        closeBtn.onclick = function () {
            masks.classList.remove('show');
        };

        // 点击遮罩层关闭弹窗
        masks.onclick = function (e) {
            if (e.target === masks) {
                masks.classList.remove('show');
            }
        };
    </script>
</body>
</html>